<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>采购入库</title>
	<!-- import css and js --> 
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
	<script src="${ctx}/js/jsp/date.js" type="text/javascript"></script>
<script type="text/javascript">
var basic_Url="${ctx}/yd/logic/qk";
var grid;
$(function(){
	
	grid = $("#table1").ligerGrid({
        columns: [
					{ display: '', name: 'id',hide:1},
                  { display: '采购编号', name: 'aktscode', width: 250,editor: { type: 'text'}},
                  { display: '用途说明', name: 'ytsm', width: 300,editor: { type: 'text'}},
                  { display: '单价', name: 'price', width: 100,editor: { type: 'float'}},
                  { display: '数量', name: 'quantity', width: 100,editor: { type: 'float'},render:function(item){
                	  if(item.price!=null&&item.quantity){
                		  grid.updateCell('zprice', ((item.price*item.quantity)).toFixed(2), item); 
                	  }
                   	  return item.quantity;
                  }},
                  { display: '总额', name: 'zprice', width: 100,editor: { type: 'float'}},
                  { display: '备注', name: 'remark', width: 230,editor: { type: 'text'}}
                  ],
                  enabledEdit: true,
                  usePager: true,pageSize:1000,pageSizeOptions:[1000],
                  width: "100%", height:250, checkbox: true,
                  toolbar: { items: [
									{ text: '增加', click: addEditRow,  icon: 'add' },
									 { line: true },
                                     { text: '删除', click: deleteRow, img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }
                                     ]
                                     }
                  });
	
	$("#pageloading").hide();
	
	$("#inputForm").validate({			   
	onsubmit: true,
	 /*执行ajaxsubmit  */ 
    submitHandler: function(editform) {
        try{			    		
            url =  basic_Url+"/save.do";
            var api = frameElement.api;
        	var W = api.opener;
            getReturnMessage(url,"inputForm",W.searchAP);
        }catch(e){alert(e)}
    }
	});

	$("#qkzl1").change(function(){ 
		  $("#qkzl").val($("#qkzl1").val());
	}); 
	
	$("#kdgs").change(function(){ 
		$("#creategsname").val($("#kdgs").find("option:selected").text());
		$("#creategscode").val($("#kdgs").val());
	}); 
	
	if('${qk.billstatus}' == ""){
		$("#save1").hide();//禁用保存按钮
	}
	if('${qk.billstatus}' == "0"){
		$("#save").hide();//禁用保存按钮
	}
	if('${qk.billstatus}' == "1" ){
		$("#save").hide();//禁用保存按钮
		$("#save1").hide();//禁用保存按钮
	}
	
	if ('${flag}' == 'ADD'){
		 $("#tr1").hide();
	}
	
	<c:forEach items='${qkitem}' var='item'>
    	grid.addRow({
    		id: "${item.id}",
    		aktscode: "${item.aktscode}",
    		ytsm: "${item.ytsm}",
    		price: "${item.price}",
    		zprice: "${item.zprice}",
    		quantity : "${item.quantity}",
    		remark : "${item.remark}"
        });
    </c:forEach>
  
})

	function addEditRow(){
		var manager = $("#table1").ligerGetGridManager(); 
		manager.addEditRow(); 
	}

	function gridfreigdeleteRow()
	{ 
		gridfreig.deleteSelectedRow();
	}

function submitForm(param){
    //设置ajax全局同步
    
	//var data = JSON.stringify(grid.getData());
	var data = grid.getData();
	var dl=grid.getDeleted();
	if(data.length==0){
		$.dialog.alert("请选择申请物料");
   	 	return false;
	}
	var ba=true;
	if(data !=null){
		var i=0;
		$(data).each(function (){
			i++;
				if (this.aktscode == ""||this.aktscode==null) {
					ba = false;
					$.dialog.alert("您第" + i + "行的采购单号没有填写");
					return false;
				}
				if (this.price == ""||this.price==null) {
					ba = false;
					$.dialog.alert("您第" + i + "行的价格没有填写");
					return false;
				}
				if (this.quantity == ""||this.quantity==null) {
					ba = false;
					$.dialog.alert("您第" + i + "行的数量没有填写");
					return false;
				}
				if (this.zprice == ""||this.zprice==null) {
					ba = false;
					$.dialog.alert("您第" + i + "行的总金额没有填写");
					return false;
				}
			});
		}
		jQuery.ajaxSettings.async = false;
		if (ba) {
			$("#itemdata").val(JSON.stringify(data));
			$("#itemdelete").val(JSON.stringify(dl));
			$("#billstatus").val(param);
			$("#inputForm").submit();
		}
	}

	function deleteRow() {
		grid.deleteSelectedRow();
	}
	function OutPut(){
		var path = basic_Url+"/output.do?id=" + $("#id").val();
	   	window.open(path,"_blank");
	}
</script>

</head>

<body>

<form id="inputForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${qk.id}"/>
<input type="hidden" id="version" name="version" value="${qk.version}"/>
<input type="hidden" id="billstatus" name="billstatus" value=""/>
<input type="hidden" id="itemdata" name="itemdata" value=""/>
<input type="hidden" id="itemdelete" name="itemdelete" value=""/>
<!-- 用于标识提交按钮 -->
<input type="hidden" id="submitFlag" value="" />
 <div class="pageContent" >
    <div class="panel">
         <table class="TableBlock" align="center">
                   <tr id="tr1">
                    <td nowrap>请款单号:</td>
   		                 <td colspan="3">
   		                <input type="text" id="qkcode" name="qkcode" disabled="disabled" class="required" value="${qk.qkcode}" />
   		                 </td>
   		           </tr>
   		           <tr>
                    <td nowrap>请款人:</td>
   		                 <td>
   		                 	<input type="text" id="qkr" name="qkr" class="required" value="${qk.qkr}"/>
   		                 	
   		                 </td>
   		                 <td nowrap>所属部门:</td>
   		                  <td>
   		                 	<input type="text" id="department" class="required" name="department" value="${qk.department}"/>
   		                 </td>
   		           </tr>
   		           <tr>
                    <td nowrap>户名:</td>
   		                 <td>
   		                 	<input type="text" id="fkfm" class="required" name="fkfm" value="${qk.fkfm}"/>
   		                 	
   		                 </td>
   		                 <td nowrap>帐号:</td>
   		                  <td>
   		                 	<input type="text" id="fkzf" class="required" name="fkzf" value="${qk.fkzf}"/>
   		                 </td>
   		           </tr>
   		           <tr>
                    <td nowrap>开户行:</td>
   		                 <td>
   		                 	<input type="text" id="fkyh" class="required" name="fkyh" value="${qk.fkyh}"/>
   		                 	
   		                 </td>
   		                 <td nowrap>行号:</td>
   		                  <td>
   		                 	<input type="text" id="fkhh" class="required" name="fkhh" value="${qk.fkhh}"/>
   		                 </td>
   		           </tr>
   		            <tr>
   		            <td nowrap>请款日期:</td>
   		                 <td>
   		                	<input type="text" id="qkrq" name="qkrq" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="required" value="<fmt:formatDate value="${qk.qkrq}" pattern="yyyy-MM-dd" type="both" />"  readonly="readonly"/>
   		                 </td>
   		                 <td nowrap>付款总类:</td>
   		                 <td><select id="qkzl1" name="qkzl1" class="required" style="width: 100px;" class="required">
   		                 	<option id="" value=''></option>
   		                 	<option id="现金" value='现金'>现金</option>
   		                 	<option id="支票" value='支票'>支票</option>
   		                 	<option id="汇票" value='汇票'>汇票</option>
   		                 	<option id="电汇" value='电汇'>电汇</option>
   		                 	<option id="转账" value='转账'>转账</option>
   		                 	</select>
   		                 	<input type="hidden" id="qkzl" name="qkzl" value="${qk.qkzl}"/>
   		                 	<script type="text/javascript">
   		                		 $("#"+'${qk.qkzl}').attr("selected","selected");
   		                 	</script></td>
   		           </tr>
   		            <tr>
   		           	<td>付款币种:</td>
   		           	<td><input id="fkml" name="fkml" class="required" value="${qk.fkml}" /></td>
   		           	 <td>开单公司:</td>
   		                 <td><select id="kdgs" name="kdgs" class="required" style="width: 300px;">
   		                 	<option id="" value=''></option>
   		                 	<c:forEach items='${bb}' var='state'>
   		                 	<option id="${state.code}" value='${state.code}'>${state.name}</option>
   		                 	</c:forEach>
   		                 	</select>
   		                 	<input type="hidden" id="creategscode" name="creategscode" value="${qk.creategscode}"/>
   		                 	<input type="hidden" id="creategsname" name="creategsname" value="${qk.creategsname}"/>
   		                 	<script type="text/javascript">
   		                		 $("#"+'${qk.creategscode}').attr("selected","selected");
   		                 	</script></td>
   		           </tr>
   		           <tr>
   		           	<td>备注:</td>
   		           	<td  colspan="3"><input style="width: 98%;" id="remark" name="remark" value="${qk.remark}" /></td>
   		           </tr>
                </table>
                <div id="table1"> </div>
         </div>
         <div class="formBar">
	        <ul>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save" onclick="submitForm(0)">保存草稿</button></div></div></li>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save1" onclick="submitForm(1)">提交</button></div></div></li>
		       <li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="OutPut()">导出</button></div></div></li>
		       <li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
	        </ul>
        </div>    
    </div>
</form>
</body>
</html>
